package me.shurufa.controller;

import android.support.v7.widget.RecyclerView;

import java.util.List;

import me.shurufa.bean.BookComment;
import me.shurufa.bean.Excerpt;
import me.shurufa.utils.Utils;

/**
 * Create by andy (https://github.com/andyxialm)
 * Create time: 16/5/23 16:50
 * Description : 书评的评论的加数量控制器。名字有点长，要不你给换一个更好的？
 */
public class BookCommentCommentCounterController {
    private RecyclerView.Adapter mAdapter;
    private List<BookComment> mDataList;
    private int mBookCommentId;

    public BookCommentCommentCounterController(RecyclerView.Adapter adapter, List<BookComment> dataList, int bookCommentId) {
        mAdapter = adapter;
        mDataList = dataList;
        mBookCommentId = bookCommentId;
    }

    public void handleAddCounter() {
        try {
            if (Utils.isNullForList(mDataList)) {
                return;
            }

            if (mBookCommentId == 0) {
                return;
            }

            // 遍历查询所有书，匹配id
            for (BookComment bookComment : mDataList) {
                if (mBookCommentId == bookComment.id) {
                    // 已查询到，判断是书摘 还是 书评, 做 +1 操作
                    int comment_num = bookComment.comment_num;
                    comment_num += 1;
                    bookComment.comment_num = comment_num;
                    break;
                }
            }
            mAdapter.notifyDataSetChanged();
        } catch (Exception e) {
        }
    }

}
